
#ifndef __PENDINA_TRX_CORE_H__
#define __PENDINA_TRX_CORE_H__

#include "pendina_trx_utils.h"

//
typedef enum _pendina_state
{
	pendina_idle_state = 0,
	pendina_setup_state,
	pendina_service_state,
	pendina_destroy_state,
	pendina_reset_state,
	pendina_exit_state,
} pendina_state;

//
class pendina_standalone_endpoint;
class pendina_standalone
{
public:
	 pendina_standalone();
	~pendina_standalone();

	//
	void reset();
	void start(bool servermode = false);
	void stop();

	bool is_server_mode() const { return is_server; }
	bool is_in_session() const { return in_session; }

	SmartPtr<NetworkStream> get_incoming_stream();
	SmartPtr<NetworkStream> get_outgoing_stream();
	void send_outgoing_stream(SmartPtr<NetworkStream> &);

private:
	pendina_standalone_endpoint *endpoint;
	bool is_server, in_session;

	pendina_state current_state;
	static void* internal_run(void *);

	//
	pendina_state pendina_run();
	void pendina_destroy();
	void pendina_service();
	void pendina_setup();
	void pendina_idle();

	//
	void raise_incoming_event(unsigned char *, unsigned int);
	void raise_outgoing_event(unsigned char *, unsigned int);
	void raise_incoming_event(SmartPtr<NetworkStream>);
	void raise_outgoing_event(SmartPtr<NetworkStream>);

	//
	SmartPtr<NetworkStream>		_incomingStream;
	SmartPtr<NetworkStream>		_outgoingStream;
	
	int _internal_id;
};

#endif
